package dem2;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2023-04-01
 * Time: 22:09
 */

class Animal{
    void eat(){
        ;
    }
}
class Dog extends Animal{
    @Override
    void eat() {
        System.out.println("狗吃骨头");
    }
}
class Cat extends Animal{
    @Override
    void eat() {
        System.out.println("猫抓老鼠");
    }
}
public class Test {

    public static void eat(Animal animal){
        if (animal instanceof Dog){
            Dog dog = (Dog) animal;
            dog.eat();
        }else if (animal instanceof Cat){
            Cat cat = (Cat) animal;
            cat.eat();
        }
    }
    public static void main(String[] args) {
        Cat cat = new Cat();
        Dog dog = new Dog();
        Animal animal = new Animal();
        eat(cat);
        eat(dog);
    }
}
